<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>css读取</title>
		<style>
			*{
				margin: 0;
				padding: 0;
			}
			div{
				height: 299px;
			
				background-color: bisque;
				font-size: 50px;
			}
			#d1{
				height: 240px;
			}
		</style>
		<script>
			function gotDiv(){
				//只能获得行内样式
				let d=document.getElementById("d1");
				alert(d.style.height);
				//计算样式是只读的
				let h=document.defaultView.getComputedStyle(d,null).height;
				alert(h);
				let w=document.defaultView.getComputedStyle(d,null).width||d.currentStyle.width;//兼容老浏览器
				alert("宽度:"+w);
			}
		</script>
	</head>
	<body>
		<div id="d1" >
			ssss
		</div>
		<p>
			<button type="button" onclick="gotDiv()">获得Div高度</button>
		</p>
	</body>
</html>